/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sddengine;

import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
 *
 * @author Jøgge
 */
abstract public class Game implements KeyListener, MouseListener, MouseMotionListener
{
    protected boolean over;

    protected int delay = 10;
    protected int width = 400;
    protected int height= 300;
    protected int arrayLength;
    protected boolean[] keyDown = new boolean[512];

    protected String title = "SddEngine 0.1";

    private BufferedImage img;
    private BufferedImage[] bufferedImage;

    abstract public void init();
    abstract public void update();
    abstract public void draw(Graphics g);
    
    public long getDelay()
    {
        return delay;
    }
  
    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    public String getTitle()
    {
        return title;
    }
 
    public boolean isOver()
    {
        return over;
    }
 /**
     *getImage method
     * 
     * parameters: name = picture location, int r/int c = how many rows and columns you want the picture to be split up by.
     * 
     * Method summary: Splits up an image into smaller parts and returns an image array which contains all the sub-images.
 * 
 */
    public BufferedImage[] getImages(String name, int r, int c)
    {
        arrayLength = (r*c);
        bufferedImage = new BufferedImage[arrayLength];
        int num = 0;
            
        try
        {
             img = ImageIO.read(new File(name));
        }
        catch (IOException e) {}

        int x = img.getWidth();   
        int y = img.getHeight();
        
        for(int i=0; i<r; i++)
        {
            for(int j=0; j<c; j++)
            {
                bufferedImage[num] = (img.getSubimage((j*(x/c)), (i*(y/r)), (x/c), (y/r)));
                num++;
            }
            
        }
        
        return bufferedImage;
    }
    
    public boolean keyDown(int keyCode)
    {
        return keyDown[keyCode];
    }
    
    public void keyTyped(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
        this.keyDown[e.getKeyCode()] = true;
    }

    public void keyReleased(KeyEvent e) {
        this.keyDown[e.getKeyCode()] = false;
    }

    public void mouseClicked(MouseEvent e) {

    }

    public void mousePressed(MouseEvent e) {

    }

    public void mouseReleased(MouseEvent e) {

    }

    public void mouseEntered(MouseEvent e) {

    }

    public void mouseExited(MouseEvent e) {

    }

    public void mouseDragged(MouseEvent e) {

    }

    public void mouseMoved(MouseEvent e) {

    }


}
